package com.obsidian.free.slideshow;

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;

public class SlideshowConfigure extends Activity implements OnClickListener {
   final static public int REQUEST_FLICKR = 1;
   final static public int REQUEST_LOCAL = 2;
   final static public int REQUEST_FLICKR_DOWNLOAD = 3;
   final static public int REQUEST_LOCAL_EDIT = 4;
   final static public int REQUEST_IMAGES = 5;

   final static public int ORDER_ORDERED = 0;
   final static public int ORDER_RANDOM = 1;
   
   final static public int TYPE_LOCAL = 0;
   final static public int TYPE_FLICKR = 1;
   
   
   
   ImageButton flickr, local;
   Button cancel;
   int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID, size;
   
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.begin);
      
      size = getIntent().getIntExtra("size", SlideshowUpdateService.SIZE_SMALL);
      appWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
      if(appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
         setResult(RESULT_CANCELED);
         finish();
         return;
      }
      
      flickr = (ImageButton)findViewById(R.id.Page1FlickrButton);
      local = (ImageButton)findViewById(R.id.Page1LocalButton);
      cancel = (Button)findViewById(R.id.Page1CancelButton);
      
      flickr.setOnClickListener(this);
      local.setOnClickListener(this);
      cancel.setOnClickListener(this);
   }

   public void onClick(View v) {
      Intent intent;
      switch(v.getId()) {
         case R.id.Page1CancelButton:
            setConfigResult(RESULT_CANCELED);
            finish();
            break;
         case R.id.Page1FlickrButton:
            intent = new Intent(this, SlideshowConfigureFlickr.class);
            intent.putExtra("appWidgetId", appWidgetId);
            intent.putExtra("size", size);
            startActivityForResult(intent, REQUEST_FLICKR);
            break;
         case R.id.Page1LocalButton:
            intent = new Intent(this, SlideshowConfigureLocal.class);
            intent.putExtra("appWidgetId", appWidgetId);
            intent.putExtra("size", size);
            startActivityForResult(intent, REQUEST_LOCAL);
            break;
      }
   }
   
   @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if(resultCode == RESULT_OK) {
         setConfigResult(resultCode);
         finish();
      }
   }
   
   private void setConfigResult(int resultCode) {
      final Intent intent = new Intent();
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
      setResult(resultCode, intent);
   }
}
